package org.jetnuke.modules.pictures;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.jforum.dao.UserDAO;
import net.jforum.entities.User;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.PictureComment;

public class LastComments implements IAction {

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		List comments=DataAccessDriver.getInst().newPictureCommentDAO().selectLastComments(10);
		Map userMap=new HashMap();
		UserDAO um=DataAccessDriver.getInst().newUserDAO();
		for(int i=0;i<comments.size();i++){
			PictureComment pc=(PictureComment)comments.get(i);
			int author=pc.getMSG_AUTHOR();
			
			Integer itn=new Integer(author);
			if(!userMap.containsKey(itn)){
				User user2=um.selectById(author);
				userMap.put(itn,user2);
			}
		}
		vc.put("userMap",userMap);
		vc.put("comments", comments);
		return new ActionForward(op,info);
	}

}
